fid = fopen('snp.txt','rt');
nLines = 0;
while (fgets(fid) ~= -1),
  nLines = nLines+1;
end
fclose(fid);
[month, day, year, open, close, high, low,volume] = textread('snp.txt','%s %d %d %f %f %f %f %f', nLines);
month=month(length(month):-1:1);
day=day(length(month):-1:1);
year=year(length(month):-1:1);
open=open(length(month):-1:1);
close=close(length(month):-1:1);
high=high(length(month):-1:1);
low=low(length(month):-1:1);
volume=volume(length(month):-1:1);
y=(close(1:length(close)-1)<=open(2:length(close)));
diffval=(close(1:length(close)-1)~=open(2:length(close)))+(open(2:length(close))~=close(2:length(close)));
month=month(diffval>0);
month_num=zeros(1,length(month));
for i=1:length(month)
    switch char(month(i))
        case 'Jan'
            month_num(i)=1;
        case 'Feb'
            month_num(i)=2;
        case 'Mar'
            month_num(i)=3;
        case 'Apr'
            month_num(i)=4;
        case 'May'
            month_num(i)=5;
        case 'Jun'
            month_num(i)=6;
        case 'Jul'
            month_num(i)=7;
        case 'Aug'
            month_num(i)=8;
        case 'Sep'
            month_num(i)=9;
        case 'Oct'
            month_num(i)=10;
        case 'Nov'
            month_num(i)=11;
        case 'Dec'
            month_num(i)=12;

    end
end

day=day(diffval>0);
year=year(diffval>0);
open=open(diffval>0);
close=close(diffval>0);
high=high(diffval>0);
low=low(diffval>0);
y=y(diffval>0);
str=[];
%fid = fopen('labeling.txt','w');
for i=1:length(open)
    str=[str, sprintf('%d %2f %2f %2f %2f %d-%02d-%02d\n',y(i),open(i),close(i),high(i),low(i),year(i),month_num(i),day(i))];
end
fid = fopen('labeling.txt','w');
fprintf(fid,str);